# 构建阶段
FROM node:20-slim as build-stage

WORKDIR /app

# 复制package.json和package-lock.json
COPY package*.json ./

# 清理可能存在的问题依赖并重新安装
RUN rm -rf node_modules package-lock.json \
    && npm cache clean --force \
    && npm install

# 复制源代码
COPY . .

# 构建应用
RUN npm run build

# 生产阶段
FROM nginx:stable as production-stage

# 复制构建好的文件到nginx目录
COPY --from=build-stage /app/dist /usr/share/nginx/html

# 复制nginx配置
COPY nginx.conf /etc/nginx/nginx.conf

# 暴露端口
EXPOSE 80

# 启动nginx
CMD ["nginx", "-g", "daemon off;"]